<?php

namespace App\Http\Controllers\Ajax;

use App\Common\Constant\Status;
use App\Services\ICookieService;
use App\Services\IMasterService;
use App\Services\IOrderService;
use App\Services\ISessionService;
use App\Services\IWalletService;
use Illuminate\Http\Request;

class ValidateController extends BaseController
{

    /**
     * 检查手机号是否已被使用
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function phoneExists(Request $request,IMasterService $masterService){
        if ($request->has('value')){
            return $this->renderJson($masterService->phoneExists($request->input('value')) ? Status::FAIL : Status::SUCCESS);
        }
        return $this->renderJson(Status::ERROR);
    }

    /**
     * 检查订单服务确认码是否正确
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function checkConfirmCode(Request $request,IOrderService $orderService){
        if ($request->has('value') && $request->has('order_id')){
            return $this->renderJson($orderService->checkConfirmCode($request->input('order_id'),$request->input('value')) ? Status::SUCCESS : Status::FAIL);
        }
        return $this->renderJson(Status::ERROR);
    }

    /**
     * 检验钱包密码
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function checkWalletPassword(Request $request,IWalletService $walletService){
        if ($request->has('value')){
            return $this->renderJson($walletService->verifyPassword(getCurrentUserid(),$request->input('value')) ? Status::SUCCESS : Status::FAIL);
        }
        return $this->renderJson(Status::ERROR);
    }
}
